package work.test01waitandnotify1;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class ParcelBox {
    /*
    定义一个包裹箱类
     */
    //包裹的数量
    private static int parcelNum = 0 ;
    //锁对象
    private static ReentrantLock lock = new ReentrantLock();
    private static Condition newDeposit = lock.newCondition();
    public ParcelBox() {
    }

    public ParcelBox(int parcelNum, ReentrantLock lock) {
        this.parcelNum = parcelNum;
        this.lock = lock;
    }

    public ParcelBox(int parcelNum, ReentrantLock lock, Condition newDeposit) {
        this.parcelNum = parcelNum;
        this.lock = lock;
        this.newDeposit = newDeposit;
    }

    public static int getParcelNum() {
        return parcelNum;
    }

    public static void setParcelNum(int parcelNum) {
        ParcelBox.parcelNum = parcelNum;
    }

    public static ReentrantLock getLock() {
        return lock;
    }

    public static void setLock(ReentrantLock lock) {
        ParcelBox.lock = lock;
    }

    //存入包裹的方法
    public static int deposit(int depositNum){
        //修改包裹数
        parcelNum += depositNum;
        return  depositNum;
    }

    //取出包裹的方法
    public static int withdraw(int withdrawNum){
        //修改包裹数
        parcelNum -= withdrawNum;
        return withdrawNum;
    }
    public static Condition getNewDeposit() {
        return newDeposit;
    }
    public static void setNewDeposit(Condition newDeposit) {
        ParcelBox.newDeposit = newDeposit;
    }

}
